home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Devil's Cubes 1.0.1 / source / Devil’s Cubes ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.8 KB  |  240 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections, including selection
  6.             of dimmed menu items (hehe).
  7.  
  8.  
  9. Devil’s Cubes -- a simple cubes puzzle
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg graphics.h"
  30. #include "msg menus.h"
  31. #include "msg sounds.h"
  32. #include "msg environment.h"
  33. #include "msg prefs.h"
  34. #include "cube.h"
  35. #include "cube load-save.h"
  36. #include "cube meat.h"
  37.  
  38. Boolean                gMenuEnabled;
  39. MenuHandle            gAppleMenu;
  40. MenuHandle            gFileMenu;
  41. MenuHandle            gEditMenu;
  42. MenuHandle            gOptionsMenu;
  43. MenuHandle            gHelpMenu;
  44.  
  45. extern    long        menuDisable : 0x0b54;
  46.  
  47. void AdjustMenus(void)
  48. {
  49.     WindowPeek    theWindow;
  50.     int            kind;
  51.     int            i;
  52.     
  53.     theWindow = (WindowPeek)FrontWindow();
  54.     kind = theWindow ? theWindow->windowKind : 0;
  55.     
  56.     if(kind < 0)
  57.         EnableItem(gEditMenu, 0);
  58.     else
  59.         DisableItem(gEditMenu, 0);
  60.     
  61.     if(theWindow)
  62.         EnableItem(gFileMenu, closeItem);
  63.     else
  64.         DisableItem(gFileMenu, closeItem);
  65.     
  66.     if(gMainWindow)
  67.     {
  68.         DisableItem(gFileMenu, newItem);
  69.         DisableItem(gFileMenu, openItem);
  70.         EnableItem(gFileMenu, saveItem);
  71.         EnableItem(gFileMenu, saveAsItem);
  72.     }
  73.     else
  74.     {
  75.         EnableItem(gFileMenu, newItem);
  76.         EnableItem(gFileMenu, openItem);
  77.         DisableItem(gFileMenu, saveItem);
  78.         DisableItem(gFileMenu, saveAsItem);
  79.     }
  80.     
  81.     CheckItem(gOptionsMenu, mirrorItem, gUseMirror);
  82.     CheckItem(gOptionsMenu, showItem, gShowAll);
  83.     
  84.     CheckItem(gOptionsMenu, soundToggle, gSoundToggle&&gSoundAvailable);
  85.     if (gSoundAvailable)
  86.         EnableItem(gOptionsMenu, soundToggle);
  87.     else
  88.         DisableItem(gOptionsMenu, soundToggle);
  89. }
  90.  
  91. void HandleMenu(long mSelect)
  92. {
  93.     int            menuID = HiWord(mSelect);
  94.     int            menuItem = LoWord(mSelect);
  95.     
  96.     if (menuID==0)
  97.     {
  98.         menuID=HiWord(menuDisable);
  99.         menuItem=LoWord(menuDisable);
  100.         gMenuEnabled=FALSE;
  101.     }
  102.     else gMenuEnabled=TRUE;
  103.     menuDisable=0L;
  104.  
  105.     switch (menuID)
  106.     {
  107.         case appleMenu:
  108.             HandleAppleMenu(menuItem);
  109.             break;
  110.         case fileMenu:
  111.             HandleFileMenu(menuItem);
  112.             break;    
  113.         case editMenu:
  114.             HandleEditMenu(menuItem);
  115.             break;
  116.         case optionsMenu:
  117.             HandleOptionsMenu(menuItem);
  118.             break;
  119.         case helpMenu:
  120.             HandleHelpMenu(menuItem);
  121.             break;
  122.       }
  123. }
  124.  
  125. void HandleAppleMenu(int menuItem)
  126. {
  127.     GrafPtr        savePort;
  128.     Str255        name;
  129.     
  130.     if(menuItem == 1)
  131.         ShowInformation();
  132.     if (menuItem == 2)
  133.         ShowSplashScreen();
  134.     else if(menuItem > 4)
  135.     {
  136.         GetPort(&savePort);
  137.         GetItem(gAppleMenu, menuItem, name);
  138.         OpenDeskAcc(name);
  139.         SetPort(savePort);
  140.     }
  141. }
  142.  
  143. void HandleFileMenu(int menuItem)
  144. {
  145.     WindowPtr        theWindow;
  146.     int                i;
  147.     
  148.     switch (menuItem)
  149.     {
  150.         case newItem:
  151.             if (gMenuEnabled)
  152.                 NewGame();
  153.             else DoSound(sound_fluff);
  154.             break;
  155.         case openItem:
  156.             if (gMenuEnabled)
  157.                 LoadSaveDispatch(TRUE, TRUE);
  158.             else DoSound(sound_fluff);
  159.             break;
  160.         case closeItem:
  161.             if (gMenuEnabled)
  162.             {
  163.                 theWindow=FrontWindow();
  164.                 for (i=0; i<NUM_HELP; i++)
  165.                     if (theWindow == gHelp[i])
  166.                         gHelp[i]=0L;
  167.                 
  168.                 if(theWindow == gMainWindow)
  169.                     CloseMainWindow();
  170.                 else
  171.                     DisposeWindow(theWindow);
  172.                 
  173.                 AdjustMenus();
  174.             }
  175.             else DoSound(sound_fluff);
  176.             break;
  177.         case saveItem:
  178.             if (gMenuEnabled)
  179.                 LoadSaveDispatch(FALSE, TRUE);
  180.             else DoSound(sound_fluff);
  181.             break;
  182.         case saveAsItem:
  183.             if (gMenuEnabled)
  184.                 LoadSaveDispatch(FALSE, FALSE);
  185.             else DoSound(sound_fluff);
  186.             break;
  187.         case quitItem:
  188.             gDone = TRUE;
  189.             break;
  190.     }
  191. }
  192.  
  193. void HandleEditMenu(int menuItem)
  194. {
  195.     if ((menuItem>0) && (menuItem!=2))
  196.     {
  197.         if (gMenuEnabled)
  198.             SystemEdit(menuItem - 1);
  199.         else DoSound(sound_fluff);
  200.     }
  201. }
  202.  
  203. void HandleOptionsMenu(int menuItem)
  204. {
  205.     switch (menuItem)
  206.     {
  207.         case mirrorItem:
  208.             gUseMirror=!gUseMirror;
  209.             SaveThePrefs();
  210.             AdjustMenus();
  211.             if (gMainWindow)
  212.                 UpdateBoard();
  213.             break;
  214.         case showItem:
  215.             gShowAll=!gShowAll;
  216.             SaveThePrefs();
  217.             AdjustMenus();
  218.             if (gMainWindow)
  219.                 UpdateBoard();
  220.             break;
  221.         case soundToggle:
  222.             if (gMenuEnabled)
  223.             {
  224.                 gSoundToggle=!gSoundToggle;
  225.                 SaveThePrefs();
  226.                 DoSound(sound_on);
  227.             }
  228.             break;
  229.     }
  230. }
  231.  
  232. void HandleHelpMenu(int menuItem)
  233. {
  234.     if ((menuItem>0) && (menuItem<=NUM_HELP))
  235.     {
  236.         OpenHelpWindow(menuItem-1);
  237.         SelectWindow(gHelp[menuItem-1]);
  238.     }
  239. }
  240.